package com.sojson.controller.po;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sojson.entity.po.TransferRecord;
import com.sojson.result.Result;
import com.sojson.service.TransferRecordService;
import com.sojson.util.token.TokenUtil;

import io.swagger.annotations.Api;

/**
 * 控制器
 * 
 * @author liu
 * @date 2021-04-23
 */
@Api(tags = "转账表管理")
@RestController
@RequestMapping("/transferRecord")
public class TransferRecordController {

    @Autowired
    private TransferRecordService transferRecordService;

    /**
     * 单条插入
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    // @PostMapping("/insert")
    public Object insert(@RequestBody TransferRecord transferRecord) throws SQLException {
        return Result.success(transferRecordService.insert(transferRecord));
    }

    /**
     * 批量插入
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    // @PostMapping("/insertList")
    public Object insertList(@RequestBody TransferRecord transferRecord) throws SQLException {
        return Result.success(transferRecordService.insertList(transferRecord));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    // @DeleteMapping("/deleteByDto")
    public Object deleteByDto(@RequestBody TransferRecord transferRecord) throws SQLException {
        return Result.success(transferRecordService.deleteByDto(transferRecord));
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException 
     */
    // @GetMapping("/countAll")
    public Object countAll() throws SQLException {
        return Result.success(transferRecordService.countAll());
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException 
     */
    // @GetMapping("/findAll")
    public Object findAll() throws SQLException {
        return Result.success(transferRecordService.findAll());
    }

    /**
     * 根据对象统计数量
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    // @GetMapping("/countByDto")
    public Object countByDto(TransferRecord transferRecord) throws SQLException {
        return Result.success(transferRecordService.countByDto(transferRecord));
    }

    /**
     * 根据对象查询
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    @GetMapping("/findByDto")
    @PreAuthorize("@ss.hasPermi('/transferRecord/findByDto')")
    public Object findByDto(TransferRecord transferRecord) throws SQLException {
        return Result.success(transferRecordService.findByDto(transferRecord));
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    // @DeleteMapping("/deleteById")
    public Object deleteById(Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteById(id));
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     */
    // @DeleteMapping("/deleteByIdList")
    public Object deleteByIdList(@RequestParam("ids") List<Integer> ids) {
        if (ids.size() == 0) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByIdList(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateById")
    public Object updateById(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateById(transferRecord));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateStaticByIdList")
    public Object updateStaticByIdList(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateStaticByIdList(transferRecord));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateChangeByIdList")
    public Object updateChangeByIdList(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateChangeByIdList(transferRecord));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updatePartialById")
    public Object updatePartialById(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updatePartialById(transferRecord));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateStaticPartialByIdList")
    public Object updateStaticPartialByIdList(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateStaticPartialByIdList(transferRecord));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateChangePartialByIdList")
    public Object updateChangePartialByIdList(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateChangePartialByIdList(transferRecord));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @GetMapping("/findById")
    @PreAuthorize("@ss.login()")
    public Object findById(Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(transferRecordService.findById(id));
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     */
    // @GetMapping("/findByIdList")
    public Object findByIdList(@RequestParam("ids[]") List<Integer> ids) {
        if (ids.size() == 0) {
            return Result.success();
        }

        return Result.success(transferRecordService.findByIdList(ids));
    }

    /**
     * 通过对象查询id列表
     * 
     * @param transferRecord
     * @return
     */
    // @GetMapping("/findIdByDto")
    public Object findIdByDto(TransferRecord transferRecord) {
        return Result.success(transferRecordService.findIdByDto(transferRecord));
    }

    /**
     * 通过orderNo删除(物理删除)
     * 
     * @param orderNo
     * @return
     */
    // @DeleteMapping("/deleteByOrderNo")
    public Object deleteByOrderNo(String orderNo) {
        if (orderNo == null) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByOrderNo(orderNo));
    }

    /**
     * 通过orderNo列表删除(物理删除)
     * 
     * @param orderNos
     * @return
     */
    // @DeleteMapping("/deleteByOrderNoList")
    public Object deleteByOrderNoList(@RequestParam("orderNos") List<String> orderNos) {
        if (orderNos.size() == 0) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByOrderNoList(orderNos));
    }

    /**
     * 通过orderNo更新(全部更新)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateByOrderNo")
    public Object updateByOrderNo(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateByOrderNo(transferRecord));
    }

    /**
     * 通过orderNo列表更新(全部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateStaticByOrderNoList")
    public Object updateStaticByOrderNoList(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateStaticByOrderNoList(transferRecord));
    }

    /**
     * 通过orderNo列表更新(全部更新)(更新内容不相同)
     * 
     * @param transferRecords
     * @return
     */
    // @PutMapping("/updateChangeByOrderNoList")
    public Object updateChangeByOrderNoList(@RequestBody TransferRecord transferRecords) {
        return Result.success(transferRecordService.updateChangeByOrderNoList(transferRecords));
    }

    /**
     * 通过orderNo更新(局部更新)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updatePartialByOrderNo")
    public Object updatePartialByOrderNo(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updatePartialByOrderNo(transferRecord));
    }

    /**
     * 通过orderNo列表更新(局部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    // @PutMapping("/updateStaticPartialByOrderNoList")
    public Object updateStaticPartialByOrderNoList(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.updateStaticPartialByOrderNoList(transferRecord));
    }

    /**
     * 通过orderNo列表更新(局部更新)(更新内容不相同)
     * 
     * @param transferRecords
     * @return
     */
    // @PutMapping("/updateChangePartialByOrderNoList")
    public Object updateChangePartialByOrderNoList(@RequestBody TransferRecord transferRecords) {
        return Result.success(transferRecordService.updateChangePartialByOrderNoList(transferRecords));
    }

    /**
     * 通过orderNo查询
     * 
     * @param orderNo
     * @return
     */
    // @GetMapping("/findByOrderNo")
    public Object findByOrderNo(String orderNo) {
        if (orderNo == null) {
            return Result.success();
        }

        return Result.success(transferRecordService.findByOrderNo(orderNo));
    }

    /**
     * 通过orderNo列表查询
     * 
     * @param orderNos
     * @return
     */
    // @GetMapping("/findByOrderNoList")
    public Object findByOrderNoList(@RequestParam("orderNos[]") List<String> orderNos) {
        if (orderNos.size() == 0) {
            return Result.success();
        }

        return Result.success(transferRecordService.findByOrderNoList(orderNos));
    }

    /**
     * 通过对象查询orderNo列表
     * 
     * @param transferRecord
     * @return
     */
    // @GetMapping("/findOrderNoByDto")
    public Object findOrderNoByDto(TransferRecord transferRecord) {
        return Result.success(transferRecordService.findOrderNoByDto(transferRecord));
    }

    /**
     * 通过对象删除(逻辑删除)
     * 
     * @param transferRecord
     * @return
     */
    // @DeleteMapping("/deleteByDtoAndUpdate")
    public Object deleteByDtoAndUpdate(@RequestBody TransferRecord transferRecord) {
        return Result.success(transferRecordService.deleteByDtoAndUpdate(transferRecord));
    }

    /**
     * 统计所有未删除的数据
     * 
     * @return
     */
    // @GetMapping("/countAllAndStatusNo")
    public Object countAllAndStatusNo() {
        return Result.success(transferRecordService.countAllAndStatusNo());
    }

    /**
     * 查询所有未删除的数据
     * 
     * @return
     */
    // @GetMapping("/findAllAndStatusNo")
    public Object findAllAndStatusNo() {
        return Result.success(transferRecordService.findAllAndStatusNo());
    }

    /**
     * 通过id删除(逻辑删除)
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/deleteByIdAndUpdate/{id}")
    @PreAuthorize("@ss.login()")
    public Object deleteByIdAndUpdate(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByIdAndUpdate(id));
    }

    /**
     * 通过id列表删除(逻辑删除)
     * 
     * @param ids
     * @return
     */
    // @DeleteMapping("/deleteByIdListAndUpdate")
    public Object deleteByIdListAndUpdate(@RequestParam("ids") List<Integer> ids) {
        if (ids.size() == 0) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByIdListAndUpdate(ids));
    }

    /**
     * 通过orderNo删除(逻辑删除)
     * 
     * @param orderNo
     * @return
     */
    // @DeleteMapping("/deleteByOrderNoAndUpdate")
    public Object deleteByOrderNoAndUpdate(String orderNo) {
        if (orderNo == null) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByOrderNoAndUpdate(orderNo));
    }

    /**
     * 通过orderNo列表删除(逻辑删除)
     * 
     * @param orderNos
     * @return
     */
    // @DeleteMapping("/deleteByOrderNoListAndUpdate")
    public Object deleteByOrderNoListAndUpdate(@RequestParam("orderNos") List<String> orderNos) {
        if (orderNos.size() == 0) {
            return Result.success();
        }

        return Result.success(transferRecordService.deleteByOrderNoListAndUpdate(orderNos));
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    // @DeleteMapping("/clear")
    public Object clear() {
        transferRecordService.clear();
        return Result.success();
    }

    /**
     * 清空数据(逻辑清空)
     * 
     * @return
     */
    // @DeleteMapping("/clearAndUpdate")
    public Object clearAndUpdate() {
        transferRecordService.clearAndUpdate();
        return Result.success();
    }

    /**
     * 根据对象查询
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     * @throws IOException 
     */
    @GetMapping("/findAppByDto")
    @PreAuthorize("@ss.login()")
    public Object findAppByDto(TransferRecord transferRecord) throws SQLException, IOException {
        transferRecord.setUserId(TokenUtil.getUserId());
        return Result.success(transferRecordService.findByDto(transferRecord));
    }

}